﻿using System.Data.Entity.ModelConfiguration;

namespace Delphi.Mimir.Data.Entities.Final.Mappings {
    public class AssetUniverseMap : EntityTypeConfiguration<AssetUniverse> {
        public AssetUniverseMap() {
            /******************************************************************
            /* Table
            /*****************************************************************/
            ToTable("fin.pfm_asset_universes");

            /******************************************************************
            /* Primary Key
            /*****************************************************************/
            HasKey(a => a.AssetUniverseId);

            /******************************************************************
            /* Index
            /*****************************************************************/
            // None

            /******************************************************************
            /* Relationships
            /*****************************************************************/
            // 1..n Exchange
            HasOptional<Exchange>(a => a.Exchange)
                .WithMany()
                .HasForeignKey(a => a.ExchangeId);

            // 1..n Symbol
            HasOptional<Symbol>(a => a.Symbol)
                .WithMany()
                .HasForeignKey(a => a.SymbolId);

            // 1..n ManagedProduct
            

            /******************************************************************
            /* Properties
            /*****************************************************************/
            Property(a => a.AssetUniverseId)
                .IsRequired()
                .HasColumnName("asu_id");

            Property(a => a.Include)
                .IsRequired()
                .HasColumnName("asu_include_fg");

            Property(a => a.SymbolId)
                .IsOptional()
                .HasColumnName("asu_sym_id");

            Property(a => a.ExchangeId)
                .IsOptional()
                .HasColumnName("asu_exc_id");

            Property(a => a.ManagedProductId)
                .IsRequired()
                .HasColumnName("asu_mpd_id");

            Property(a => a.ValidFromDate)
                .IsRequired()
                .HasColumnName("asu_valid_frm_dt");

            Property(a => a.ValidUntilDate)
                .IsRequired()
                .HasColumnName("asu_valid_til_dt");
        }
    }
}
